from .PackageStream import PackageStream


class MatcherBase:

    def __init__(this, matchCallback=None):
        """
        matchCallback:func(bytes) 接收到数据包后引发的callback
        """
        this.stream = PackageStream()
        this._matchCallback = matchCallback

    def SetMatchCallback(this, matchCallback):
        """
        matchCallback:func(bytes) 接收到数据包后引发的callback
        """
        this._matchCallback = matchCallback

    def InvokeMatchCallback(this, buf: bytes):
        """引发回调"""
        this._matchCallback(buf)

    def EncodeData(this, data: bytes) -> bytes:
        """数据包编码实现，由派生类实现"""
        pass

    def InStream(this, data: bytes):
        """数据输入,由派生类实现"""
        pass

    def Reset(this):
        """重置,重写时需要base.Reset()，清空stream"""
        this.stream.clear()
